//
//  PlaytourViewController.m
//  一点互助
//
//  Created by 张泊秋 on 16/8/20.
//  Copyright © 2016年 zhangboqiu. All rights reserved.
//

#import "PlaytourViewController.h"
#import "PlaytourCustomCell.h"
#import "ResponseManager.h"
#import "ResponseManager+Playtour.h"


static NSString *playtourIdentifier = @"playtourTableViewCell";
@interface PlaytourViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataSoure;

@end

@implementation PlaytourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"我的打赏";
    
    [self setupBackItem];
    [self.view addSubview:self.tableView];
}

- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [userDefaults objectForKey:@"userInfo"];
    
    [ResponseManager getPlaytourInfoUserId:dic[@"id"] completionHandler:^(FBResponse *response) {
        if (response.success) {
            
            self.dataSoure = response.resultValue;
            [self.tableView reloadData];
            
        }else {
            NSLog(@"%@",response.resultDesc);
        }
        
    }];
    
    
}
- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSoure.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PlaytourCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:playtourIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataSoure[indexPath.row];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1 * kScreenHeightScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80 * kScreenHeightScale;
}


- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        UINib *nib = [UINib nibWithNibName:@"PlaytourCustomCell" bundle:nil];
        [_tableView registerNib:nib forCellReuseIdentifier:playtourIdentifier];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        
    }
    return _tableView;
}

- (NSMutableArray *)dataSoure {
    if (!_dataSoure) {
        _dataSoure = [NSMutableArray array];
        
    }
    return _dataSoure;
}

@end
